Skip to content

LeetCode #19: Remove Nth Node From End of List#139

Merged
WazedKhan merged 1 commit into
mainfrom
leetcode-19-linked-list
Jun 28, 2026
Merged

LeetCode #19: Remove Nth Node From End of List#139
WazedKhan merged 1 commit into
mainfrom
leetcode-19-linked-list

Conversation

@WazedKhan

@WazedKhan WazedKhan commented Jun 28, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features
    • Added a solution for removing the Nth node from the end of a linked list, including support for edge cases like deleting the first node.

@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

A new file LeetCode/medium/remove_nth_from_end_19.py is added with a ListNode class and a Solution class containing a length helper and removeNthFromEnd method that uses a dummy head node to remove the target node.

Changes

Remove Nth Node From End

Layer / File(s) Summary
ListNode and Solution implementation
LeetCode/medium/remove_nth_from_end_19.py
Defines ListNode, a length helper to count nodes, and removeNthFromEnd which computes the removal index from a dummy head and bypasses the target node.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Poem

🐇 Hop along the linked list trail,
Count the nodes without fail,
Dummy head leads the way,
One node skipped — hip hooray!
The rabbit solves LeetCode today! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately names the LeetCode #19 problem implemented in the pull request.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch leetcode-19-linked-list

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
LeetCode/medium/remove_nth_from_end_19.py (1)

11-11: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Make the helper signature match its caller.

removeNthFromEnd passes Optional[ListNode] into length, so the current annotation is stricter than the actual contract.

♻️ Proposed fix
-    def length(self, head: ListNode) -> int:
+    def length(self, head: Optional[ListNode]) -> int:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@LeetCode/medium/remove_nth_from_end_19.py` at line 11, The helper method
length has a type signature that is stricter than what removeNthFromEnd actually
passes, since it may receive a missing head node. Update the length method
annotation to accept the same Optional[ListNode] contract used by
removeNthFromEnd, and keep its implementation unchanged so it can safely handle
a null head input.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@LeetCode/medium/remove_nth_from_end_19.py`:
- Around line 5-7: Rename the ListNode initializer parameter in the ListNode
class from next to a non-builtin name and update the assignment accordingly;
make the change in the __init__ method so the constructor signature and any
internal references no longer shadow the builtin name.

---

Nitpick comments:
In `@LeetCode/medium/remove_nth_from_end_19.py`:
- Line 11: The helper method length has a type signature that is stricter than
what removeNthFromEnd actually passes, since it may receive a missing head node.
Update the length method annotation to accept the same Optional[ListNode]
contract used by removeNthFromEnd, and keep its implementation unchanged so it
can safely handle a null head input.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6b3ed49a-dcaf-42f6-ae4e-35fab9fe7781

📥 Commits

Reviewing files that changed from the base of the PR and between 64552b3 and cc5a842.

📒 Files selected for processing (1)
  • LeetCode/medium/remove_nth_from_end_19.py

Comment on lines +5 to +7
def __init__(self, val=0, next=None):
self.val = val
self.next = next

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Rename next to avoid builtin shadowing.
This keeps lint noise down and avoids reusing a builtin name.

🧰 Tools
🪛 Ruff (0.15.18)

[error] 5-5: Function argument next is shadowing a Python builtin

(A002)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@LeetCode/medium/remove_nth_from_end_19.py` around lines 5 - 7, Rename the
ListNode initializer parameter in the ListNode class from next to a non-builtin
name and update the assignment accordingly; make the change in the __init__
method so the constructor signature and any internal references no longer shadow
the builtin name.

@WazedKhan WazedKhan merged commit 32d4ab4 into main Jun 28, 2026
3 checks passed
@WazedKhan WazedKhan deleted the leetcode-19-linked-list branch June 28, 2026 15:51
@coderabbitai coderabbitai Bot mentioned this pull request Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant